<?php

namespace app\home\controller;

use app\home\model\pyg_cart;
use app\home\model\pyg_category;
use app\home\model\pyg_spec_goods;
use app\Request;
use think\facade\Db;
use think\facade\Session;
use think\View;

class Shopping
{
    public function addShopping(Request $request)
    {
        $id = $request->get('id');
        $number = $request->get('number');
        cache('idS',$id);
        cache('numberS',$number);
        if(Session('name')=="")
        {
            return json([
               'code'=>'600',
               'msg'=>'',
               'data'=>'',
            ]);
        }
        $obj = new pyg_spec_goods();
        $res = $obj->with('Shopping')->find($id)->toArray();
        $data = [
            'user_id'=>Session('id'),
            'goods_id'=>$res['Shopping']['id'],
            'number'=>$number,
            'spec_goods_id'=>$res['id'],
            'is_selected'=>'1',
        ];
//        dd($data);
        $obe = new pyg_cart();
        $obe->add($data);
        return success('添加成功');
    }
    public function success()
    {
        $obj = new pyg_category();
        $res = $obj->showCategory()->toArray();
        $showCategory = get_tree_list($res);

        $obj = new pyg_spec_goods();
        $res = $obj->with('Shopping')->find(cache('idS'))->toArray();
        $data = [
            'goods_name'=>$res['Shopping']['goods_name'],
            'number'=>cache('numberS'),
            'value_names'=>$res['value_names'],
        ];
        return \think\facade\View::fetch('cart/success-cart',['showCategory'=>$showCategory,'data'=>$data]);
    }
}